package com.itheima.test;

import com.baidu.aip.face.AipFace;
import org.json.JSONObject;
import org.junit.Test;

import java.util.HashMap;

public class FaceTest1 {//人脸识别测试
    //设置APPID/AK/SK
    public static final String APP_ID = "25739014";
    public static final String API_KEY = "1XokOGjWe3WPEsLP1qX8OEU9";
    public static final String SECRET_KEY = "tVOmEASWpQgowTGTyKjHMwglxXQ0UCjM";
    @Test
    public void test(){
        // 初始化一个AipFace
        AipFace client = new AipFace(APP_ID, API_KEY, SECRET_KEY);

        // 可选：设置网络连接参数
        client.setConnectionTimeoutInMillis(2000);
        client.setSocketTimeoutInMillis(60000);


        // 调用接口
        String image = "https://tanhua-six.oss-cn-beijing.aliyuncs.com//2022/03/10/be486e21-0836-4955-b1a6-25612cd1376e.jpg";
        String imageType = "URL";

        HashMap<String, String> options = new HashMap<String, String>();
        options.put("face_field", "age");
        options.put("max_face_num", "2");
        options.put("face_type", "LIVE");
        options.put("liveness_control", "LOW");

        // 人脸检测
        JSONObject res = client.detect(image, imageType, options);
        System.out.println(res.toString(2));
    }
}
